#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/6/30 22:23
# @USER    : Shengji He
# @File    : LCOF.py
# @Software: PyCharm
# @Version  : Python-
# @TASK:
class Stack:
    def __init__(self):
        self.stack = []

    def push(self, value):
        self.stack.append(value)

    def is_empty(self):
        return not self.stack

    def pop(self):
        if self.is_empty():
            return False
        else:
            self.stack.pop()
            return True

    def top(self):
        return self.stack[-1]


class CQueue:
    """
    用两个栈实现一个队列。队列的声明如下，请实现它的两个函数 appendTail 和 deleteHead ，分别完成在队列尾部插入整数和在队列头部
    删除整数的功能。(若队列中没有元素，deleteHead 操作返回 -1 )

    示例 1：
        输入：
            ["CQueue","appendTail","deleteHead","deleteHead"]

            [[],[3],[],[]]
        输出：
            [null,null,3,-1]
    示例 2：
        输入：
            ["CQueue","deleteHead","appendTail","appendTail","deleteHead","deleteHead"]

            [[],[],[5],[2],[],[]]
        输出：
            [null,-1,null,null,5,2]

    提示：
        - 1 <= values <= 10000
        - 最多会对 appendTail、deleteHead 进行 10000 次调用
    """

    # def __init__(self):
    #     self.stack1 = Stack()
    #     self.stack2 = Stack()
    #
    # def appendTail(self, value: int) -> None:
    #     self.stack1.push(value)
    #
    # def deleteHead(self) -> int:
    #     if self.stack2.is_empty():
    #         while not self.stack1.is_empty():
    #             self.stack2.push(self.stack1.top())
    #             self.stack1.pop()
    #     if self.stack2.is_empty():
    #         return -1
    #     else:
    #         deleteItem = self.stack2.top()
    #         self.stack2.pop()
    #         return deleteItem
    def __init__(self):
        self.A = []
        self.B = []

    def appendTail(self, value: int) -> None:
        self.A.append(value)

    def deleteHead(self) -> int:
        if self.B:
            return self.B.pop()
        if not self.A:
            return -1
        while self.A:
            self.B.append(self.A.pop())

        return self.B.pop()


if __name__ == '__main__':
    S = CQueue()
    print('done')
